package org.thingsboard.server.dao.tenantIp;



import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.TenantIp;
import org.thingsboard.server.dao.model.sql.CamerasInfo;
import org.thingsboard.server.dao.model.sql.TenantIpEntity;


import java.util.List;
import java.util.Map;


@Service
@Slf4j
public class TenantIpServiceImpl implements TenantIpService {

    @Autowired
    private TenantIpDao tenantIpDao;


    /**
     * 根据设备名称获取场地ip
     *
     * @param deviceName
     * @return
     */
    @Override
    public String getIpByDeviceName(String deviceName) {
        return tenantIpDao.getIpByDeviceName(deviceName);
    }

    /**
     * 根据当前登入人获取服务器ip
     *
     * @param tenantName
     * @return
     */
    @Override
    public String getIpByLoginUser(String tenantName) {
        return tenantIpDao.getIpByLoginUser(tenantName);
    }


    /**
     * 获取租户所有摄像头信息
     *
     * @param tenantName
     * @return
     */
    @Override
    public String getCamerasByTenantName(String tenantName) {
        JSONObject cameraJson = new JSONObject();
        List<CamerasInfo> cameras = tenantIpDao.getCameras(tenantName);
        String camerasJson = JSONObject.toJSONString(cameras);
        cameraJson.put("cameraInfos", camerasJson);
        return camerasJson;
    }

    @Override
    public Map getCamerasIdByDeviceName(String device) {
        return tenantIpDao.getCamerasIdByDeviceName(device);
    }

    @Override
    public List<TenantIp> getIpAndPwd() {
        return tenantIpDao.getIpAndPwd();
    }


}
